/*
 * @Author: 陈国庆 2306727047@qq.com
 * @Date: 2023-12-09 11:01:33
 * @LastEditors: 陈国庆 2306727047@qq.com
 * @LastEditTime: 2023-12-11 18:07:21
 * @FilePath: \boke7.0\boke-server\src\user\user.service.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from 'src/dataBase/Entities/user.entity';
import { Repository } from 'typeorm';

/**
 * 用户服务
 */
@Injectable()
export class UserService {
  constructor(
    @InjectRepository(User)
    private usersRepository: Repository<User>,
  ) {}
  /**
   * 查询所有数据
   * @returns
   */
  findAll(): Promise<User[]> {
    return this.usersRepository.find();
  }
  findOne(id: number): Promise<User | null> {
    return this.usersRepository.findOneBy({ id });
  }
  /**
   * 查找用户
   * @param username
   * @returns
   */
  findUsername(username: string): Promise<User | null> {
    return this.usersRepository.findOneBy({ username });
  }
  save(user: User): Promise<User> {
    return this.usersRepository.save(user);
  }
  async remove(id: number): Promise<void> {
    await this.usersRepository.delete(id);
  }
  GetUser() {
    return {
      name: '123',
    };
  }
}
